import json
from api.base_service import BaseService


class UserService(BaseService):
    def __init__(self):
        super().__init__()
        self.service_name = "UserService"

    def find_by_username(self, username):
        resp = self.client.invoke(self.service_name, "findByUsername", username)
        # 成功("admin"): "{}"   查不到用户("admin1"):"null" 数据类型错误(123): "Failed"
        if resp == "null" or resp == "Failed":
            return None
        else:
            return json.loads(resp)


if __name__ == '__main__':
    us = UserService()
    resp = us.find_by_username("admin")
    print("响应信息:", resp)
    print("响应类型:", type(resp))
